<!DOCTYPE html>
<html>

	<head lang="en">
		<meta charset="UTF-8">
		<title>注册</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />

		<link rel="stylesheet" href="AmazeUI-2.4.2/assets/css/amazeui.min.css" />
		<link href="css/dlstyle.css" rel="stylesheet" type="text/css">
		<script src="AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
		<script src="AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>
		
		
		<script type="text/javascript" src="js/vue2.5.js"></script>
		<script type="text/javascript" src="js/axios.min.js"></script>
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/global.js"></script>
		<script type="text/javascript" src="js/bootstrap/js/bootstrap.js"></script>
		<script src="js/layer/layer.js"></script>

	</head>

	<body>
		<div class="container">
			<div class="login-boxtitle">
				<a href="home/demo.html"><img alt="" src="images/logo2.png" /></a>
			</div>

			<div class="res-banner">
				<div class="res-main">
					<div class="login-banner-bg"><span></span><img src="images/big.jpg" /></div>
					<div class="login-box">

						<div class="am-tabs" id="doc-my-tabs">
							<ul class="am-tabs-nav am-nav am-nav-tabs am-nav-justify">
								<li class="am-active"><a href="">用户注册</a></li>
								
							</ul>

							<div class="am-tabs-bd">
								<div class="am-tab-panel am-active">
									<form method="post">

										<div class="user-email">
											<label for="email"><i class="am-icon-user"></i></label>
											<input type="text" @change="checkLoginName()" v-model="user.LoginName" id="LoginName" name="LoginName" placeholder="请输入用户名">
										</div>
										<div class="user-pass">
											<label for="password"><i class="am-icon-lock"></i></label>
											<input type="password" v-model="user.Pwd" id="Pwd" name="Pwd" placeholder="设置密码">
										</div>
										<div class="user-pass">
											<label for="passwordRepeat"><i class="am-icon-lock"></i></label>
											<input type="password" v-model="user.Pwd2" id="Pwd2" name="Pwd2" placeholder="确认密码">
										</div>

									</form>

									<div class="login-links">
										<label for="reader-me">
											<input  type="checkbox" id="agree" name="agree"  checked> 点击表示您同意商城<a href="Rules.txt" >《服务协议》</a>
										</label>
									</div>
									<div class="am-cf">
										<input type="submit" name="" id="addBtn" value="注册" class="am-btn am-btn-primary am-btn-sm am-fl" @click="add()">
									</div>

								</div>

								

							</div>
						</div>

					</div>
				</div>
			</div>
			<div class="footer ">
				<div class="footer-hd ">
					<p>
						<a href="home.html">商城首页</a>
						<b>|</b>

					</p>
				</div>

			</div>
		</div>
		<script>
			var vue = new Vue({
				el: '.container',
				data: {
					user: {

					}
				},
				methods: {

					//查询登录名是否存在
					checkLoginName: function() {
						if (this.user.LoginName == '')
							return;
						axios.get(baseUrl + '/user/check', {
								params: {
									LoginName: this.user.LoginName
								}
							})
							.then(function(response) {
								console.log(response.data);
								if (response.data) {
									layer.msg('用户名已经占用');
									return false;
								} else
									layer.msg('用户名可以使用');

							}.bind(this))
							.catch(function(error) {
								layer.msg('检查用户名失败');
							});
					},

					//注册会员
					add: function() {

						if (!checkForm())
							return;

						axios.post(baseUrl + '/user/register', $.param(this.user))
							.then(function(response) {
								layer.msg('注册成功');
								location.href = "login.html";
							}.bind(this))
							.catch(function(error) {
								layer.msg('注册失败');
							});
					}
				}

			});

			//表单验证函数
			function checkForm() {

				//登录名称
				var LoginName = $('#LoginName');

				if (LoginName.val() == '' || LoginName.val().length > 10) {
					layer.msg('登录名不能为空，且最多10字符');
					LoginName.focus();
					return false;
				}

				//密码验证
				var Pwd = $('#Pwd');
				var Pwd2 = $('#Pwd2');

				if (Pwd.val() == '') {
					layer.msg('密码不能为空');
					Pwd.focus();
					return false;
				}

				if (Pwd2.val() != Pwd.val() || Pwd2.val() == '') {
					layer.msg('两次密码必须相同');
					Pwd2.focus();
					return false;
				}
				
				return true;
			}

			//检查是否选中同意用户须知
			$(function() {
				$('#agree').click(function() {
					if ($('#agree').is(':checked')) {
						$("#addBtn").attr("disabled", false);
					} else {
						$("#addBtn").attr("disabled", true);
					}
				});
			});
		</script>
	</body>

</html>